


import { ref, createApp } from "vue";
import TradingTable from "@/content-scripts/components/table/TradingTable.vue";
import Antd from "ant-design-vue";

let perpetualApp = null

export async function creatrecordeorder(params={}) {
    const container =
        document.querySelector(".mantine-gy53ll")
    const { tableSource, tableColumns } = await getBottomTableList(params)

    if (!container) {
        console.log('未找到.scroll-table-bottom-box > .table-scroll-window > div > .tr-table__wrapper，表格区域');
    }

    const existingOverlay = container.querySelector(".my-perpetual-table-overlay");
    if (existingOverlay) {
        existingOverlay.remove();
    }

    const overlay = document.createElement("div");
    overlay.setAttribute("class", "my-perpetual-table-overlay");
    overlay.setAttribute(
        "style",
        "position: absolute;\n" +
        " left: 0;\n" +
        " top: 0;\n" +
        " width: 100%;\n" +
        " height: 100%;\n" +
        " z-index: 35;\n" +
        " background: white;\n"
    );

    const tableStyle = {
        // fontSize: "12px",
        color: "#8e949e",
        // background: "#F8F9FB",
    };

    // 挂载元素
    const appContainer = document.createElement("div");

    perpetualApp = createApp(TradingTable);
    perpetualApp.provide("tableSource", tableSource);
    perpetualApp.provide("tableColumns", tableColumns);
    perpetualApp.provide("tableStyle", tableStyle);
    perpetualApp.use(Antd);
    perpetualApp.mount(appContainer);

    container.style.position = "relative";
    overlay.appendChild(appContainer);
    container.appendChild(overlay);
}

import {recordCol} from '@/content-scripts/components/table/columns/perpetualColumns.js'
import {get} from "@/http/http";

async function getBottomTableList(params) {
    let tableSource = ref([])
    let tableColumns = ref([])
    const dataSource = await get('/perpetual/position/list',params)
    console.log(dataSource, 'dataSource');
    tableSource = dataSource.data
    tableColumns = recordCol
    return { tableSource, tableColumns }
}